#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2025 粤港澳大湾区（广东）国创中心

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

File: PythonConsoleDlg.py
Desc: A dialog window that serves as a Python console within the application.
Author: xumanjia
Date: 2025-08-01
"""
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QTextEdit, QPushButton

class QTextEditLogger:
    def __init__(self, text_edit):
        self.text_edit = text_edit

    def write(self, message):
        # 将信息添加到 QTextEdit 控件
        self.text_edit.append(message)
        cursor = self.text_edit.textCursor()
        cursor.movePosition(cursor.End)
        self.text_edit.setTextCursor(cursor)


    def flush(self):
        # 必须实现 flush 方法
        pass

class PythonConsoleDlg(QTextEdit):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.init_ui()
        self.setWindowTitle("控制台")
        self.NCTI = parent.NCTI
        self.setStyleSheet("background-color: #FFFFFF; color: #3D3D3D; font-family: monospace;")
        
        
    def init_ui(self):
        i=0

    def add_text(self,text):
        self.append(f"\n{text}")